package com.cheer.ba.view.adapter;

import android.app.Activity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cheer.ba.R;
import com.cheer.ba.model.OilPriceModel;
import com.cheer.ba.utils.LogUtils;
import com.cheer.ba.utils.SystemUtils;
import com.cheer.ba.widget.myrecycleview.BaseHolder;

public class HomeOilPriceHolder extends BaseHolder<OilPriceModel> {

    LinearLayout mRecycleRoot;

    //油价
    TextView mTxtOilPrice;
    //油类型
    TextView mTxtOilType;

    public HomeOilPriceHolder(ViewGroup parent, int resId) {
        super(parent, resId);
        mRecycleRoot = getView(R.id.id_oil_price_root_view);

        mTxtOilPrice = getView(R.id.id_oil_price_txt);
        mTxtOilType = getView(R.id.id_oil_type_txt);
    }

    @Override
    public void setData(OilPriceModel data) {
        if (null != data) {
            mTxtOilPrice.setText(data.oilPrice + "元");
            mTxtOilType.setText(data.oilName);
            LogUtils.LogD("oilprice", data.oilName + "--" + data.oilPrice);
            if (data.isRed()) {
                mTxtOilPrice.setTextColor(getContext().getResources().getColor(R.color.red));
            } else {
                mTxtOilPrice.setTextColor(getContext().getResources().getColor(R.color.color_333333));
            }
        }
    }

    @Override
    public void getCount(int size) {
        if (size > 0) {
            int width = SystemUtils.getScreenWidth((Activity) getContext());
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width / 5, LinearLayout.LayoutParams.MATCH_PARENT);
            mRecycleRoot.setLayoutParams(params);
        }
    }
}